import axios from "axios";

export default {
  state: {
    tableData: [],
  },
  getters: {},
  mutations: {
    SET_TABLE_DATA(state, data) {
      state.tableData = data;
    },
  },
  actions: {
    getListAction({ commit }) {
      return axios({
        url: "http://localhost:4000/posts",
      }).then((res) => {
        commit("SET_TABLE_DATA", res.data);
      });
    },
    deleteArticleAction(context, id) {
      return axios({
        method: "DELETE",
        url: "http://localhost:4000/posts/" + id,
      });
    },
    createArticleAction(context, data) {
      return axios({
        method: "POST",
        url: "http://localhost:4000/posts",
        data,
      });
    },
    getArticleAction(context, id) {
      return axios({
        url: "http://localhost:4000/posts/" + id,
      });
    },
    updateArticleAction(content, { data, id }) {
      return axios({
        method: "PUT",
        url: "http://localhost:4000/posts/" + id,
        data,
      });
    },
  },
  namespaced: true,
};
